Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Get all mentors endpoint (Admin) #24 #67

Merged
merged 4 commits into from
Oct 8, 2023

Conversation

sathudeva7
Copy link
Contributor

Purpose

The purpose of this PR is to fix #24

Goals

This issue involves implementing an API to get all mentors. The endpoint should allow Admin to make a GET request to {{baseUrl}}/api/admin/mentors?status={{status}}.

Approach

```const mentorsList: Mentor[] = await mentorRepository.find({
  where: { state: status },
  select: [
    'application',
    'availability',
    'state',
    'created_at',
    'updated_at'
  ],
  relations: ['profile', 'category']
})
This api endpoint request application json in a different format so created a function with switch case according to json question function return specific key for the application object in the response

### Screenshots
<!---  Include an animated GIF or screenshot if the change affects the UI.  -->
![Screenshot 2023-10-04 at 12 46 32](https://github.com/sef-global/scholarx-backend/assets/67930416/18daa379-b961-418a-8cb9-e7c4316e8956)


##  Checklist
- [x] This PR doesn't commit any keys, passwords, tokens, usernames, or other secrets.
- [x] I have read and understood the development best practices guidelines ( http://bit.ly/sef-best-practices )
- [ ] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation

## Related PRs
<!--- List any other related PRs --> 

## Test environment
<!--- List all versions, operating systems, databases, and browser/versions on which this feature/fix was tested --> 

## Learning
<!--- Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem. -->

@sathudeva7 sathudeva7 marked this pull request as draft October 4, 2023 18:08
@sathudeva7 sathudeva7 marked this pull request as ready for review October 4, 2023 18:08
@sathudeva7
Copy link
Contributor Author

Screenshot 2023-10-04 at 12 46 32

let adminAgent: supertest.SuperAgentTest
let mentorId: string

describe('getAllMentors function', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be route testing. Move to the src/routes/admin/mentor/mentor.route.test.ts file

status: ApplicationStatus
): Promise<{
statusCode: number
mentors?: AllMentorsArray[]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do have the Mentor interface. Use that.

Suggested change
mentors?: AllMentorsArray[]
mentors?: Mentor[]

const mentorRepository = dataSource.getRepository(Mentor)

const mentorsList: Mentor[] = await mentorRepository.find({
where: { state: status },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status is optional, by default it will return all the mentors if the status is not present

src/services/admin/mentor.service.ts Outdated Show resolved Hide resolved
Comment on lines 75 to 84
const mentors: AllMentorsArray[] = mentorsList.map((mentor, i) => {
Object.entries(mentor.application).map((item) => {
switchQuestion(item, applicationFormat)
})
return {
...mentor,
mentor_id: i + 1,
application: applicationFormat,
category: mentor.category.category,
state: mentor.state.toUpperCase()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this as well. Just return the mentors

Suggested change
const mentors: AllMentorsArray[] = mentorsList.map((mentor, i) => {
Object.entries(mentor.application).map((item) => {
switchQuestion(item, applicationFormat)
})
return {
...mentor,
mentor_id: i + 1,
application: applicationFormat,
category: mentor.category.category,
state: mentor.state.toUpperCase()

src/types.ts Outdated Show resolved Hide resolved
src/types.ts Outdated Show resolved Hide resolved
src/routes/admin/mentor/mentor.route.test.ts Outdated Show resolved Hide resolved
src/controllers/admin/mentor.controller.ts Outdated Show resolved Hide resolved
Copy link
Member

@anjula-sack anjula-sack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! @sathudeva7

@anjula-sack anjula-sack merged commit 6764e21 into sef-global:main Oct 8, 2023
1 check passed
sathudeva7 added a commit to sathudeva7/scholarx-backend that referenced this pull request Oct 8, 2023
Implement Get all mentors endpoint (Admin) sef-global#24 (sef-global#67)
anjula-sack pushed a commit to anjula-sack/scholarx-backend that referenced this pull request Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Get all mentors endpoint (Admin)
2 participants